<%@ page language="java" import="java.util.*" import="java.text.SimpleDateFormat" pageEncoding="UTF-8"%>
<%@ page import="com.bluesky.light.user.*" %>
<%@ page import="com.bluesky.light.staff.*" %>
<%@ page import="com.bluesky.light.product.*" %>
<%@ page import="com.bluesky.light.order.*" %>
<%
	request.setCharacterEncoding("UTF-8");
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	// check if the user is login
	Staff s = (Staff)session.getAttribute("staff");
	if (s == null) {
		response.sendRedirect("/light");
		return;
	}	
	String name = s.getName();
%>
<%
	User u = (User)session.getAttribute("user");
%>
<%
	String action = request.getParameter("action");
	List<TreatItem> items = null;
	TreatOrder order = null;
	if (action != null && action.trim().equals("getinfo")) {
		order = OrderService.getInstance().getOrder(u, "trd");
		if (order == null) {
			out.println("No Payment Have to Pay");
			return;
		}
		items = order.getItems();
//System.out.println(items.size());
	}
	
	Double totalPrice = 0.0;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>light</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="css/main.css" rel="stylesheet" type="text/css" />
	
  </head>
  
  <body>
	<!-- header -->
	<div id="header">
		<div id="logo"><img src="images/logo_small2.png"/></div>
	</div>
	<!-- // header -->
	<!-- nav -->
	<div id="nav">
	</div>
	<!-- // nav -->
	<!-- container -->
	<div id="container">
		<!-- contents -->
		<div id="contents">
	    	<div id="menu">
	        	<div>
	        		<div id="user_info">
	            		<img src="develop/user_icon.jpg"/> 
	            		<b>Finance</b>
	           		</div>
	           		<div>
	           		<%=name%>
	           		</div>
	           		<div>
	            	<%SimpleDateFormat sdf = new SimpleDateFormat("EEE, yyyy-MM-dd", new Locale("US"));%><%=sdf.format(new Date())%><br></br>
	            	</div>
	            </div>
	        	<ul>
	            	<li><a href="finance/home.jsp"><img src="images/news.png" /> Health News</a></li>
					<li><a href="finance/staff_userSearch.jsp"><img src="images/surscribe.png" /> User search</a></li>
					<li><a href="finance/staff_infoModifyInput.jspsp"><img src="images/account.png" /> Account Management</a></li>               
					<li><a href="index.jsp"><img src="images/account.png" /> logout</a></li> 
	            </ul>
	        </div>
	        <div id="main-cont">
	            <div id="result">
	            <form method="post" action="finance/staff_userCheckOut.jsp">
		                <table class="resulttable" rules="all" >
		                	<caption>Prescription</caption>
		                	<tr><th colspan="4">User info.</th></tr>
							<tr><td>Id.</td><td colspan="3"><%=u.getId()%></td></tr>
							<tr><td>Name</td><td colspan="3"><%=u.getName()%></td></tr>
							<tr><td>Sex</td><td colspan="3"><%=u.getSex()%></td></tr>
							<tr><td>Age</td><td colspan="3"><%=u.getBirth()%></td></tr>
							<tr><th colspan="4">Medicine List</th></tr>
							<tr><th>Name</th><th>Dose</th><th>Unit Price</th><th>Price</th>
							<%
								for (Iterator<TreatItem> it = items.iterator(); it.hasNext();) {
									TreatItem ti = it.next();
					//System.out.println(ti);
									Double itemPrice = ti.getUnitPrice() * ti.getCount();
									totalPrice += itemPrice;
							%>
							<tr>
								<td><%=ti.getProduct().getName()%></td>
								<td><%=ti.getCount()%>mg</td>
								<td><%=ti.getUnitPrice()%></td>
								<td><%=itemPrice %></td>
							</tr>
							<%
								}
							%>
							<tr>
								<td colspan="2">Total Price</td>
								<td colspan="2"><%=totalPrice%></td>
							</tr>
							<tr>
								<td colspan="4">
								<input type="hidden" name="action" value="checkout"/>
								<input type="hidden" name="treatorderid" value="<%=order.getId()%>"/>
								<input type="submit" value="Check Out"/>
								</td>
							</tr>
		                </table>	
		        </form>	
	        	</div>	        	
	    </div>
	    <!-- // contents -->
	</div>
	<!-- // container -->
	</div>
	<div id="footer">
		<div id="bs_stdio">
	    	©2011-2011 www.bluesky.com.mo All Rights Reserved<br/>
	    	<img src="images/bluesky_logo.png" />
	    </div>
	</div>
  </body>
</html>
